const express = require('express');
const router = express.Router();
const db = require('../../../../util/dbConfig/dbConfig')

router.delete('/',async (req,res) => {
    if(req.session.userInfo.admin !==1 || !req.session.userInfo){
        return res.send({
            code: 3,
            msg: '非管理员权限或未登录'
        })
    }
    let {
        ID,  //绒质信息编号
        sheepId,                        //羊只编号
        specimen,                       //样品编号
    } = req.body
    //判断三个参数是否存在和是否有值
    if(!ID || !sheepId || !specimen){
        return res.send({
            code: 1,
            msg: '参数错误'
        })
    }
    let arr = []
    try{
        let dSql = `delete from sheepftne  where ID=${ID} and SHEEP_ID=${sheepId} and SPECIMEN=${specimen}`
        let result = await db.SySqlConnect(dSql,arr)
        if(result['affectedRows'] !== 1){
            return res.send({
                code: 2,
                msg: '删除失败'
            })
        }
        return res.send({
            code: 0,
            msg: '删除成功'
        })
    }catch (e) {
        console.log(e);
        return res.send({
            code: 4,
            msg: '服务器错误，请稍后再试'
        })
    }
})

module.exports = router
